/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Visitor;
import Functii.*;
/**
 *
 * @author AlinT
 */

import Arbori.Nod;
import Functii.Constanta;
import Functii.Cos;
import Functii.Exp;
import Functii.Log;
import Functii.Necunoscuta;
import Functii.Sin;
import Operatori.Cat;
import Operatori.Minus;
import Operatori.Plus;
import Operatori.Produs;


public class ToStringVisitor extends Visitor{
	String s;

	public void visit(Plus p) {
		if ( p.getfStang() != null && p . getfDrept() != null )
		{
		visit(p.getfStang()) ;
		String s1=this.s;
		visit ( p.getfDrept() ) ;
		String s2=this.s ;
		s=p.concatTermeni( s1 , s2 ) ;
		}

	}

	public ToStringVisitor() {
		super();
		this.s = "";
	}

	public ToStringVisitor(String s) {
		super();
		this.s = s;
	}

	public String getS() {
		return s;
	}

	public void setS(String s) {
		this.s = s;
	}

	public void visit(Minus m) {
		if ( m.getfStang() != null && m . getfDrept() != null )
		{
		visit(m.getfStang()) ;
		String s1=this.s ;
		visit ( m.getfDrept() ) ;
		String s2=this.s ;
		s=m.concatTermeni( s2 , s1 ) ;
		}

	}

	public void visit(Cat c) {
		if ( c.getfStang() != null && c . getfDrept() != null )
		{
		visit(c.getfStang()) ;
		String s1=this.s ;
		visit ( c.getfDrept() ) ;
		String s2=this.s ;
		s=c.concatTermeni( s1 , s2 ) ;
		}

	}

	public void visit(Produs p) {
		if ( p.getfStang() != null && p . getfDrept() != null )
		{
		visit(p.getfStang()) ;
		String s1=this.s ;
		visit ( p.getfDrept() ) ;
		String s2=this.s ;
		s=p.concatTermeni( s1 , s2 ) ;
		}

	}


	public void visit(Necunoscuta n) {
		this.s="X";

	}

	public void visit(Constanta c) {
		this.s=Double.toString(c.getCt());

	}


	public void visit(Sin s) {
		if ( s.getfStang() != null )
		{
			visit(s.getfStang());
			String s1=this.s;
			this.s=s.concatTermeni(s1);
		}

	}

	public void visit(Cos c) {
		if ( c.getfStang() != null )
		{
			visit(c.getfStang());
			String s1=this.s;
			this.s=c.concatTermeni(s1);
		}

	}

	public void visit(Nod n) {
		if ( n instanceof Necunoscuta ) this.visit((Necunoscuta)n);
		if ( n instanceof Constanta ) this.visit((Constanta)n);
		if ( n instanceof Plus ) this.visit((Plus)n);
		if ( n instanceof Minus ) this.visit((Minus)n);
		if ( n instanceof Cat ) this.visit((Cat)n);
		if ( n instanceof Produs ) this.visit((Produs)n);
		if ( n instanceof Sin ) this.visit((Sin)n);
		if ( n instanceof Cos ) this.visit((Cos)n);
		if ( n instanceof Tg ) this.visit((Tg)n);
		if ( n instanceof Ctg ) this.visit((Ctg)n);
                if ( n instanceof Putere) this.visit((Putere)n);
		if ( n instanceof Radical ) this.visit((Radical)n);
		if ( n instanceof Log ) this.visit((Log)n);
		if ( n instanceof Exp ) this.visit((Exp)n);

	}

	public void visit(Tg t) {
		if ( t.getfStang() != null )
		{
			visit(t.getfStang());
			String s1=this.s;
			this.s=t.concatTermeni(s1);
		}

	}

	public void visit(Ctg c) {
		if ( c.getfStang() != null )
		{
			visit(c.getfStang());
			String s1=this.s;
			this.s=c.concatTermeni(s1);
		}

	}

	public void visit(Log l) {
		if ( l.getfStang() != null )
		{
			visit(l.getfStang());
			String s1=this.s;
			this.s=l.concatTermeni(s1);
		}

	}

        public void visit(Putere p) {
		if ( p.getfStang() != null )
		{
			visit(p.getfStang());
			String s1=this.s;
                        System.out.println("->");
			this.s=p.concatTermeni(s1);
		}

	}

	public void visit(Exp e) {
		if ( e.getfStang() != null )
		{
			visit(e.getfStang());
			String s1=this.s;
			this.s=e.concatTermeni(s1);
		}

	}

	public void visit(Radical r) {
		if ( r.getfStang() != null )
		{
			visit(r.getfStang());
			String s1=this.s;
			this.s=r.concatTermeni(s1);
		}

	}

}
